import java.util.Arrays;

class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}




public class Test2 {
    public static void main(String[] args) {
        String str = " hello hello     ";
        String ret = str.trim();//去除左右两边的空格
        boolean flg = str.contains("hello");
        System.out.println(flg);
        System.out.print(ret);
        System.out.println("pppppppp");
        String str2 = "abcabcdabcdef";
        System.out.println(str2.endsWith("cdef"));//判断是否以这个字符串结尾
        System.out.println(str2.startsWith("a"));
    }

    public static void main5(String[] args) {
        //字符串截取
        String str = "helloworld";
        String ret = str.substring(1);
        System.out.println(ret);
        String ret1 = str.substring(1,5);//左闭右开
        System.out.println(ret1);
    }


    public static void main4(String[] args) {
        //字符串拆分
//        String s1 = "zhangsan&wanwu&lisi&zhaoliu";
//        String[] s2 = s1.split("&");
//        String[] s3 = s1.split("&",2);
//        for (String x : s2){
//            System.out.println(x);
//        }
//        System.out.println(Arrays.toString(s3));
//        System.out.println(Arrays.toString(s2));
//          String str = "zhangsan&wanwu&zhaoliu&lisi";
//          String[] ret = str.split("&");
//        System.out.println(Arrays.toString(ret));
//          String str2 = "127.2.2.1";
//          String[] ret2 = str2.split("."); //.为特殊字符，需要用\\进行转义
//        System.out.println(Arrays.toString(ret2));
//        for (String x : ret2){
//            System.out.println(x);
//        }
//            String str3 = "127\\3\\3\\1";
//            String[] ret3 = str3.split("\\\\");
//        System.out.println(Arrays.toString(ret3));
//        for (String x : ret3){
//            System.out.println(x);
//        }
        String str4 = "name=zhangsan&age=18";
        String[] ret4 = str4.split("&|=");//法1
        System.out.println(Arrays.toString(ret4));
        //法2
        String[] ret5 = str4.split("&");
        for (String x : ret5){
            String[] ss = x.split("=");
            for(String s :ss){
                System.out.println(s);
            }
        }
    }




    //字符串替换
    public static void main3(String[] args) {
        String str1 = String.format("%d-%d-%d",2022,9,14);
        System.out.println(str1);
        String s1 = "ababcabcdabcdef";
        String s2 = s1.replace("abc","de");
        System.out.println(s2);
String s3 = s1.replace("a","c");
        System.out.println(s3);
        String s4 = s1.replaceAll("abc","adsa");
        System.out.println(s4);
        String s5 = s1.replaceFirst("abc","fgh");
        System.out.println(s5);
    }

    public static void main2(String[] args) {
        //字符串大小写转换
        String s1 = "hellOaB我";
        String s2 = "HELLow我";
        System.out.println(s1);
        System.out.println(s1.toUpperCase());
        System.out.println(s2.toLowerCase());
        System.out.println("==================");
        char[] char2 = s2.toCharArray();
        System.out.println(char2);
        System.out.println(Arrays.toString(char2));
        int[] array = {1,2,3,4};
        System.out.println(array);
    }


    public static void main1(String[] args) {
        for (int i = 0; i < args.length; i++) {
            System.out.println(args[i]);
        }
        //字符串转换
        String str = String.valueOf(123);
        System.out.println(str);
        String s2 = String.valueOf(true);
        System.out.println(s2);
        String s3 = String.valueOf(new Student("heimama",18));
        System.out.println(s3);
        System.out.println("==================================");
        int vall = Integer.parseInt("1234");
        System.out.println(vall);
        double ac = Double.valueOf("123.12");
        System.out.println(ac);
        double ads = Double.parseDouble("123.34");
        System.out.println(ads);
    }

}
